package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.domain.ClassQuerParam;
import com.itheima.domain.PageResult;
import com.itheima.domain.pojo.Clazz;
import com.itheima.mapper.ClazzMapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.service.ClazzService;
import org.apache.coyote.Request;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
@Service
public class ClazzServiceImpl implements ClazzService {
    @Autowired
    private ClazzMapper clazzMapper;
    @Autowired
    private EmpMapper empMapper;

    @Override
    public List<Clazz> list() {
        return  clazzMapper.list();
    }

    @Override
    public void add( Clazz clazz) {
        clazz.setCreateTime(LocalDateTime.now());
        clazz.setUpdateTime(LocalDateTime.now());
        clazzMapper.insert( clazz);

    }

    @Override
    public PageResult<Clazz> page(ClassQuerParam classQuerParam) {
        PageHelper.startPage(classQuerParam.getPage(),classQuerParam.getPageSize());
        List<Clazz> clazzlist = clazzMapper.lists(classQuerParam);
        Page<Clazz> p=(Page<Clazz>) clazzlist;
        return new PageResult(p.getTotal(),p.getResult());
    }

    @Override
    public void delete(Integer id) {
        clazzMapper.delete(id);
    }
//数据回显
    @Override
    public Clazz selectById(Integer id) {
        clazzMapper.selectById(id);
        return  clazzMapper.selectById(id);
    }

    @Override
    public void update(Clazz clazz) {
        clazz.setUpdateTime(LocalDateTime.now());
        clazzMapper.updateById(clazz);
    }
}
